//
//  Ext.swift
//  web
//
//  Created by 张卓 on 2017/1/16.
//  Copyright © 2017年 ZZ. All rights reserved.
//

import UIKit

//构造函数
//分类
extension UIBarButtonItem{
    
    //便利构造函数
    convenience init(image: String? = nil, title: String? = nil, target: Any?, action: Selector){
        self.init()
        //创建一个button
        let bnt = UIButton()
        if let img = image {
            //设置图片
            bnt.setImage(UIImage(named:img), for: UIControlState.normal)
            bnt.setImage(UIImage(named:"\(img)_highlighted"), for: UIControlState.highlighted)
        }
        if let tit = title {
            bnt.setTitle(tit, for: UIControlState.normal)
            bnt.setTitleColor(UIColor.gray, for: UIControlState.normal)
            bnt.setTitleColor(ZZThemeColor, for: UIControlState.highlighted)
            bnt.setTitleColor(UIColor.black, for: UIControlState.disabled)
            bnt.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        }
        //添加按钮点击事件
        bnt.addTarget(target,action: action, for: UIControlEvents.touchUpInside)
        //设置大小
        bnt.sizeToFit()
        customView = bnt
        
    }
    
    
    
    
    
    
    
}



